<? // ajax

//-phpinfo();
//-exit;

// debugging
//-$buf = '';
//-foreach( $_SERVER as $key=>$val ) $buf .= "$key = $val\n";
//-echo $buf;
//-exit;

function inMsg( $msg ) {
	$keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	//-echo "msg = \"$msg\"<br/>";
	$mix = $_SESSION['cur_hash'] + $_SESSION['rand'];
	//-echo "mix = \"$mix\"<br/>";

	$seed = decoct( 0+$mix );
	//-echo "hash = $mix, seed = \"$seed\"<br/>";
	$msg2 = '';
	for( $ct=0; $ct<strlen($msg); $ct++ ) {
		//-echo "offset: 0 , ct=$ct, mod=".($ct%(strlen($seed)-1))." substr=".substr( $seed, $ct%(strlen($seed)-1), 2 )."<br/>";
		$sub = substr( $seed, $ct%(strlen($seed)-1), 2 );
		$offset = octdec( $sub );
		$ch = strpos($keyStr,$msg[$ct]);
		//-echo "ct=$ct, ch=$ch, sub=$sub, offset=$offset<br/>";
		$val = ($ch + (64-$offset)) % 64;
		//-echo "offset=$offset, val=$val<br/>";
		$msg2 .= $keyStr[$val];
		//-echo "msg2 = $msg2<br/>";
	}
	//-echo "msg2 = \"$msg2\"<br/>";
	$out = rtrim(base64_decode($msg2));
	//-echo "out = \"$out\"<br/>";

	return $out;
}

$_fileref = substr($_SERVER['REDIRECT_URL'],2);

// pull out 
if( $_fileref != 'init' && $_SESSION['cur_hash'] ) {
	foreach( $_GET as $key=>$value ) 	$_GET = (Array)(json_decode(inmsg($key),true));
	foreach( $_POST as $key=>$value )	$_POST = (Array)(json_decode(inMsg($key),true));

	/* DEPRICATED if no GET or POST, we're mud
	if( !count($_GET) && !count($_POST) ) {
		// todo: change 404 into something more meaningful
		header( 'HTTP/1.0 404 Not Found' );
		ajax_exit( 'error', "unable to checksum" );
	}
	*/

	//-print_r( $_GET );
	include "../ajax/".substr($_SERVER['REDIRECT_URL'],2).".php";
	//-exit;
}

// ajax action file
include "../ajax/".substr($_SERVER['REDIRECT_URL'],2).".php";

exit;

?>
